﻿using System;
using System.Web.Optimization;

namespace McKearney.BundlingTweaks
{
    public class InstrumentedBundleTransform : IBundleTransform
    {
        readonly IBundleTransform _impl;

        public InstrumentedBundleTransform(IBundleTransform impl)
        {
            if (impl == null)
            {
                throw new ArgumentNullException("impl");
            }
            _impl = impl;
        }
        #region IBundleTransform Members

        public void Process(BundleContext context, BundleResponse response)
        {
            // save old value
            bool enable = context.EnableInstrumentation;

            // enable it
            context.EnableInstrumentation = true;
            _impl.Process(context, response);

            // remove it, just in case it would screw something up
            context.EnableInstrumentation = enable;
        }

        #endregion
    }
}